package de.jmda.sample.navigate;

import static de.jmda.core.mproc.ProcessingUtilities.getPackageOf;
import static de.jmda.core.mproc.ProcessingUtilities.isProcessingOver;
import static de.jmda.core.util.CollectionsUtil.asSet;

import java.io.IOException;
import java.util.Collection;
import java.util.Set;

import javax.lang.model.element.Element;

import de.jmda.core.mproc.task.AbstractTypeElementsTaskTypes;
import de.jmda.core.mproc.task.TaskException;
import de.jmda.core.mproc.task.TaskRunner;

/**
 * Navigate containment hierarchy.
 *
 * @author roger
 */
class Containment
{
	class InnerType { InnerType innerFieldInInnerType; }
	
	InnerType innerFieldInOuterType;
	
	public static void main(String[] args) throws TaskException, IOException
  {
		Task task = new Task(asSet(Containment.class));
		TaskRunner.run(task);;
  }
}

class Task extends AbstractTypeElementsTaskTypes
{
	public Task(Set<? extends Class<?>> types) { super(types); }

	@Override
  public boolean execute() throws TaskException
  {
		if (false == isProcessingOver())
		{
			// print containment hierarchy of first type element's package
			printContainment(asSet(getPackageOf(getTypeElements().iterator().next())));
		}

		return false;
  }

	private void printContainment(Collection<? extends Element> elements)
	{
		for (Element element : elements)
		{
			System.out.println(element.asType() + " " + element.getSimpleName());

			printContainment(element.getEnclosedElements());
		}
	}
}